from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine,Column,Integer,String
from conf.settings import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class User(Base):
    __tablename__ = 'user_test_info'
    id = Column(Integer, primary_key=True)
    username = Column(String(32), index=True)
    key = Column(String(64))

SQLALCHEMY_DATABASE_URL = f"mysql+pymysql://{DBConfig['spider']['USER']}:{DBConfig['spider']['PASSWORD']}@{DBConfig['spider']['HOST']}:{DBConfig['spider']['PORT']}/{DBConfig['spider']['DATABASE']}?charset=utf8mb4"

engine = create_engine(SQLALCHEMY_DATABASE_URL, max_overflow=5)
Session = sessionmaker(autocommit=False, autoflush=False, bind=engine)
session = Session()

a = session.query(User).filter(User.username == 'aron').first()
print(a.username)